package com.wangsd.web.sys.service;

import com.gitee.fastmybatis.core.query.Query;
import com.wangsd.web.sys.entity.SysButton;
import com.wangsd.web.sys.mapper.SysButtonMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysButtonService {
    @Resource
    SysButtonMapper mapper;

    /**
     * 查询所有按钮
     * @return
     */
    public List<SysButton> selectList() {
        return mapper.list(new Query());
    }

    public List<SysButton> selectListByMenuId(Long menuId) {
        return mapper.listByColumn("menu_id", menuId);
    }
    public int deleteById(Long id) {
        return mapper.deleteById(id);
    }
    /**
     * 根据菜单id删除所有按钮
     * @param menuId
     */
    public int deleteByMenuId(Long menuId) {
        Query query = new Query();
        query.eq("menu_id", menuId);
        return mapper.deleteByQuery(query);
    }
    public int save(SysButton entity) {
        return mapper.saveIgnoreNull(entity);
    }

    public int saveBatch(List<SysButton> buttonList) {
        return mapper.saveBatch(buttonList);
    }
}
